package net.wanho.shiro.realm;

import net.wanho.shiro.token.JwtToken;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
/**
 * Author：汤小洋
 * Date：2023-07-25 16:46
 * Description：<描述>
 */
public class ShiroRealm extends AuthorizingRealm {

    /**
     * 支持自定义的JwtToken
     * @param token the token being submitted for authentication.
     * @return
     */
    @Override
    public boolean supports(AuthenticationToken token) {
        return token instanceof JwtToken;
    }

    /**
     * 认证
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken jwtToken) throws AuthenticationException {
       return new SimpleAuthenticationInfo(
               jwtToken.getPrincipal(),
               null,
               getName()
       );
    }

    /**
     * 授权
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
       return null;
    }

}
